package com.reborn.mall.api.service.impl;

import com.reborn.mall.api.model.entity.Brand;
import com.reborn.mall.api.model.entity.Product;
import com.reborn.mall.api.service.BrandService;
import com.reborn.mall.api.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * TODO: Here is description
 *
 * @author wu.yue
 * @since 2020/1/18
 */
@Service
public class BrandServiceImpl extends BaseServiceImpl<Brand> implements BrandService {

    @Autowired
    private ProductService productService;

    @Override
    public List<Brand> find(Brand entity) {
        List<Brand> brands = super.find(entity);
        for (Brand brand : brands) {
            Product p = new Product();
            p.setBrandId(brand.getId());
            List<Product> products = productService.find(p);
            brand.setProductCount(products.size());
        }
        return brands;
    }

}
